<template>
  <div>
    <div class="main col">
      <div class="head row">
        <div class="imgB"> 
          <img width="100" height="100" :src="`${url}`+`${userInfo.ppictureAddr}`" alt="" />
        </div>
        <div class="col message">
          <div class="name">{{ userInfo.name }}</div>
          <div class="infoList">
            <template v-for="(item, index) in attr">

<!-- 
              <i v-if="item.type == 'input'"><input
                  :ref="'menu'+index"
                  :disabled="!item.change"
                  :class="{'value':true,'inputs':item.change}"
                  v-model="userInfo[item.attr]"
                  @blur="change(index)"
                ></input><i class="change" @click="toChange(index)">修改</i>
              </i> -->



              <div class="item">
                <i
                  :class="[
                    'icon',
                    userInfo[item.attr] == ''
                      ? 'el-icon-success void'
                      : 'el-icon-warning yes',
                  ]"
                ></i>
                <i class="lable">{{ item.name }}:</i>
                <!-- <i class="value">{{ userInfo[item.attr] }}</i> -->

                <!-- <input
                  :disabled="!item.change"
                  :class="{'value':true,'inputs':item.change}"
                  v-model="userInfo[item.attr]"
                  @blur="change(index)"
                ></input> -->
                <input
                  :ref="'menu'+index"
                  :disabled="!item.change"
                  :class="{'value':true,'inputs':item.change}"
                  v-model="userInfo[item.attr]"
                  @blur="change(index)"
                ></input>

                <i class="change" @click="toChange(index)">修改</i>
              </div>
            </template>
          </div>
        </div>
      </div>
      <div class="mains">
        <template v-for="item in more">
          <div class="moreList">
            <div class="title">{{item.title}}</div>
            <div class="moreInfo">
              <template v-if="item.code=='tip'" v-for=" ite in item.values">
                <div  class="tip">
                  <i class="type">{{ite.type}}:</i>
                  <template v-for="it in ite.value">
                    <i class="value"><i>{{it.name}}</i><i>({{it.num}})</i></i>
                  </template>
                </div>
              </template>
              <div v-if="item.code!='tip'" class="listrow">
              <template  v-for="ite in item.values">
                
                <div  class="notip">
                  <div class="type">{{ite.type}}</div>
                  <div class="value"><i>{{ite.value}}</i></div>
                </div>
                
              </template>
              </div>
            </div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: localStorage.getItem("url"),
      userInfo: {
        ppitureAddr: "", //头像地址
        userId: 0,
        name: "",
        sex: "",
        username: "",
        password: "",
        email: "",
        qq: "",
        phone: "",
        desctiption: "", //描述（喜好）
        address: "",
        state: "", //状态
        spendingTime: "", //在线时长

        // ppitureAddr: require("@/assets/imgs/logo.png"), //头像地址
        // userId: 0,
        // name: "小李",
        // sex: "男",
        // username: "aa用户",
        // password: "123",
        // email: "email",
        // qq: "123456",
        // phone: "123456",
        // desctiption: "学无止境", //描述（喜好）
        // address: "17栋111",
        // state: "2", //状态
        // spendingTime: "", //在线时长
      },
      attr: [
        { name: "昵称", attr: "username", code: "", change: false },
        { name: "地址", attr: "address", code: "", change: false },
        { name: "QQ", attr: "qq", code: "", change: false },
        { name: "手机", attr: "phone", code: "", change: false },
      ],
      more: [
        // {
        //   title: "我的资金账户",
        //   code: "money",
        //   values: [
        //     { type: "余额", value: 100, code: "" },
        //     { type: "余额", value: 100, code: "" },
        //     { type: "余额", value: 100, code: "" },
        //   ],
        // },
        {
          title: "交易提醒",
          code: "tip",
          //  1下单  2商家确认 - 交换联系信息    自行线下交易  3商家确认交货  4买家确认收获 已完成  5用户申请取消  6商家取消 7已取消
          values: [
            {
              type: "店铺订单",
              value: [
                { name: "待确认", num: 1 },
                { name: "待交易", num: 1 },
                { name: "待买家确认收获", num: 1 },
                { name: "已完成", num: 1 },
                { name: "我取消", num: 1 },
                { name: "已取消", num: 1 },
              ],
            },
            {
              type: "购买订单",
              value: [
                { name: "待商家确认", num: 1 },
                { name: "待交易", num: 1 },
                { name: "待确认收获", num: 1 },
                { name: "已完成", num: 1 },
                { name: "取消中", num: 1 },
                { name: "已取消", num: 1 },
              ],
            },
          ],
        },
        {
          title: "我的商品",
          code: "myGoods",
          values: [
            { type: "收藏人数", value: 100 },
            { type: "商品总数", value: 100 },
            { type: "总销售量", value: 100 },
            { type: "总购买量", value: 100 },
          ],
        },
      ],
    };
  },
  created() {
    this.$axios
      .get("sys/user/getUserByUserId/" + this.$store.state.user.user.userId)
      .then(({ data }) => {
        console.log("myHome: uer: userInfo=", data.userInfo);
        this.userInfo = data.userInfo;
      });
  },
  methods: {
    toChange(index) {
      this.attr[index].change = true;
      this.$nextTick(() => {
        this.$refs[`menu${index}`][0].focus();
      });
    },
    change(index) {
      this.attr[index].change = false;
      this.$axios
        .post("sys/user/updataByUserInfo", this.userInfo)
        .then(({ data }) => {
          if (data.code == 201) {
            this.$message.success("修改成功");
          }
          this.userInfo = data.userInfo;
        });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  width: 100%;
  .head {
    // background: rgb(215, 101, 101);
    .imgB {
      margin-right: 40px;
    }
    .message {
      width: calc(100% - 12px);
    }
    .name {
      font-weight: 600;
      padding-bottom: 20px;
    }
    .infoList {
      // background: #000;
      .item {
        width: 50%;
        display: inline-block;
        margin-top: 16px;
        color: lightslategrey;
        font-size: 14px;
        .icon {
          margin-right: 10px;
        }
        .yes {
          color: lightgreen;
        }
        .void {
          color: lightcoral;
        }
        .lable {
          color: dimgray;
        }
        .value {
          outline: none;
          display: inline;
          margin-left: 10px;
          margin-right: 10px;
          border: none;
          width: 100px;
          overflow: hidden;
        }
        .inputs {
          border: 1px solid lightsteelblue;
        }
        .change {
          font-size: 10px;
          color: rgb(148, 175, 222);
        }
        .change:hover {
          cursor: pointer;
          color: rgb(236, 60, 60);
        }
      }
    }
  }
}
.mains {
  margin-top: 30px;
  .moreList {
    border: 1px solid lightgrey;
    margin-top: 10px;
    .title {
      font-weight: 600;
      line-height: 2;
      padding-left: 10px;
      background: rgb(224, 232, 246);
    }
    .moreInfo {
      padding-left: 10px;
      margin-top: 16px;
      margin-bottom: 16px;
      // display: flex;
      .tip {
        line-height: 2;
        .type {
          font-size: 14px;
          margin-right: 18px;
        }
        .value {
          font-size: 12px;
          color: lightslategrey;
          margin-right: 14px;
        }
      }
      .listrow {
        display: flex;
        flex-flow: row nowrap;
        text-align: center;
        // background: red;
        .notip {
          flex: 1;
          .type {
            margin-bottom: 10px;
          }
          .value {
            font-size: 20px;
          }
        }
      }
    }
  }
}
.value {
  outline: none;
  display: inline;
  margin-left: 10px;
  margin-right: 10px;
  border: none;
  width: 100px;
  overflow: hidden;
}
.inputs {
  border: 1px solid lightsteelblue;
}
</style>